/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
 */

/**
 * Created by liuhui
 */
define([ 'adminapp'], function ($app) {
    $app.navactive('activity_brand');

    var preview_tpl = Handlebars.compile($('#showpics-template').html());


    $app.initEditor('textarea#description');
    $app.uploader({
        'uploader'       : g.ctx + 'file/up?dpi=bacvtity',
        'buttonText'     : '点击上传图片',
        'width'          : 140,
        'queueSizeLimit' : 10,
        'onUploadSuccess': function (file, data, response) {
            var jsonData = eval('(' + data + ')');
            if (jsonData['status'] == 'OK') {
                var attachement_path = jsonData['data'];
                var $moPrictures = $('#mo_prictures');
                var val = $moPrictures.val();
                if (val) {
                    $moPrictures.val((val + ",") + attachement_path);
                } else {
                    $moPrictures.val(attachement_path);
                }
                $('#picture-grid').append(preview_tpl({ctx: g.ctx, data: attachement_path.replace('.', '.thumbnail.'), preview: attachement_path}))
            }
        }
    }, 'prictureAttachmentUpload');

    $app.formvalidator({
        'activity.name'       : {
            required : true,
            maxlength: 30
        },
        'activity.is_enroll'  : {
            required: true
        }
    }, 'brandForm');

    return {};
});
